package com.cd.learn.cdlearn.pattern.combination;

import org.assertj.core.util.Lists;

import java.util.List;

/**
 * @ClassName Menu
 * @Description 树菜单的菜单项，拥有下一级，树枝节点
 * @Author seven
 * @Date 2021/7/421:12
 * @Version 1.0
 **/
public class Menu extends MenuComponent {

    private List<MenuComponent> menuComponents = Lists.newArrayList();


    public Menu(){}
    public Menu(String name,Integer level){
        this.level = level;
        this.name = name;
    }


    @Override
    public void add(MenuComponent menuComponent) {
       menuComponents.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponents.remove(menuComponent);
    }

    public List<MenuComponent> getMenuComponents(){
        return menuComponents;
    }


    @Override
    public void showName() {
        for (Integer i = 0; i < level; i++) {
            System.out.print("-");
        }
        System.out.println(this.name);
        menuComponents.forEach(MenuComponent::showName);
    }

    @Override
    public MenuComponent getChildren(int i) {
        return menuComponents.get(i);
    }


}
